package config;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class properties {

    public static void main(String[] args) {
        Properties p = new Properties();
        try {
            // 加载配置文件
            p.load(new FileInputStream("src/config.properties"));

            // 获取属性值
            String username = p.getProperty("username");
            String pwd = p.getProperty("pwd");

            // 输出属性值
            System.out.println(
                    "username=" + username + " " +
                            "pwd=" + pwd
            );

            // 设置属性值
            p.setProperty("age", "gangMan18");
            p.setProperty("school", "JiaLiDun");

            // 保存属性值
            p.store(new FileOutputStream("src/config.properties"), null);

            // 输出属性值
            System.out.println(
                   p.stringPropertyNames()
            );

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


}
